package com.cy.store.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component //将当前类的创建维护交由spring容器来维护
@Aspect //将当前类作为切面类
public class TimerAspect {

    @Around("execution(* com.cy.store.service.impl.*.*(..))")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {//连接点：目标对象
        //先记录当前时间
        Long start = System.currentTimeMillis();

        Object result = pjp.proceed(); //调用目标方法

        //后记录当前时间
        Long end = System.currentTimeMillis();
        System.out.println("耗时：" + (end - start));
        return result;
    }

}
